package com.ldu.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * Created by yangxiang on 16/6/28.
 */
@AllArgsConstructor
public enum CommonStatusEnum {

    NO(0, "否", "超级管理员", "禁用"),

    YES(1, "是", "系统管理员", "启用"),
    ;

    @Getter
    private Integer code;

    @Getter
    private String name;

    @Getter
    private String roleName;

    @Getter
    private String statusDesc;

    public static CommonStatusEnum get(int code) {
        for (CommonStatusEnum attr : CommonStatusEnum.values()) {
            if (attr.getCode() == code) {
                return attr;
            }
        }
        throw new IllegalArgumentException("No such status.");
    }

    public static String getNameByCode(Integer code) {
        for (CommonStatusEnum attr : CommonStatusEnum.values()) {
            if (attr.getCode() == code) {
                return attr.getName();
            }
        }
        return null;
    }

    public static CommonStatusEnum get(String name) {
        if (null == name || ("").equals(name.trim())) {
            return null;
        }
        for (CommonStatusEnum attr : CommonStatusEnum.values()) {
            if (name.equals(attr.getName())) {
                return attr;
            }
        }
        throw new IllegalArgumentException("No such status.");
    }

    public static String getRoleNameByCode(Integer code) {
        if (null == code) {
            return null;
        }
        CommonStatusEnum[] values = CommonStatusEnum.values();
        for (CommonStatusEnum value : values) {
            if (value.getCode().equals(code)) {
                return value.getRoleName();
            }
        }
        return null;
    }

    public static String getStatusDescByCode(Integer code) {
        if (null == code) {
            return null;
        }
        CommonStatusEnum[] values = CommonStatusEnum.values();
        for (CommonStatusEnum value : values) {
            if (value.getCode().equals(code)) {
                return value.getStatusDesc();
            }
        }
        return null;
    }

}
